package com.zekdot.fileclient.action;

import com.zekdot.fileclient.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Create by zekdot on 20-3-29.
 */
@Controller
@RequestMapping("/file")
public class FileAction {

    @Autowired
    private FileService fileService;

    /**
     * 上传其他文件
     * @param userId 用户id
     * @param file 文件
     * @param maxSize 最大尺寸
     * @return
     */
    @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
    @ResponseBody
    public String uploadFile(String userId,@RequestParam(value = "file") MultipartFile file,
                             @RequestParam(value = "maxSize",defaultValue = "32")int maxSize){
        return fileService.saveFile(file,userId,maxSize).toString();
    }
    /**
     * 上传图片文件
     * @param userId 用户id
     * @param pic 图片文件
     * @param maxSize 最大容量
     * @return
     */
    @RequestMapping(value = "/uploadPic",method = RequestMethod.POST)
    @ResponseBody
    public String uploadPic(String userId,@RequestParam(value = "pic") MultipartFile pic,
                            @RequestParam(value = "maxSize",defaultValue = "32")int maxSize){
        return fileService.savePic(pic,userId,maxSize).toString();
    }

    /**
     * 上传base64编码的图片文件
     * @param picCode 编码后的图片
     * @param userId 用户id
     * @param maxSize 最大容量
     * @return
     */
    @RequestMapping(value = "/uploadPicByCode",method = RequestMethod.POST)
    @ResponseBody
    public String uploadPicByCode(String picCode,String userId,int maxSize){
        return fileService.savePic(picCode, userId, maxSize).toString();
    }
}
